package aex.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;
/**
 * 基础的action所有的action应该继承这个action
 * 这个action提一些实用的方法，比如获得request  和response。
 * @author JiangYouYao
 *
 */
public class BaseActon extends ActionSupport implements ServletRequestAware,ServletResponseAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected HttpServletRequest request=null;
	protected HttpServletResponse response=null;
	
	public String basePath;
	
	
	
	
  	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response=response;
		response.setCharacterEncoding("utf-8");
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request=request;
		String path = request.getContextPath();
		basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		
		
	}
	/**
	 * 向客户端输出一段信息
	 * @param msg
	 */
	public void ajaxPrint(String msg){
		try {
			response.getWriter().write(msg);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
